Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
JavaScript. 10%5 === 0 --> ¿falso?

Por favor ayuda a encontrar errores en mi código:

 function multipleOfIndex(array) { return array.forEach( item => console.log(item%array.indexOf(item) === 0) ) } console.log(multipleOfIndex([68, -1, 1, -7, 10, 10])) // false, true, false, false, false, false

obviamente, estaba esperando

 console.log(multipleOfIndex([68, -1, 1, -7, 10, 10])) // false, true, false, false, false, true

¡Gracias!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

El problema es confiar en indexOf cuando más de un valor es el mismo en la matriz: array.indexOf(10) siempre es 4 , consulte el registro ampliado aquí:

 function multipleOfIndex(array) { return array.forEach( item => console.log(item,array.indexOf(item),item%array.indexOf(item) === 0) ) } console.log(multipleOfIndex([68, -1, 1, -7, 10, 10])) // false, true, false, false, false, false

La solución es usar el parámetro index forEach (2º) https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

 function multipleOfIndex(array) { return array.forEach( (item,idx) => console.log(item%idx === 0) ) } console.log(multipleOfIndex([68, -1, 1, -7, 10, 10])) // false, true, false, false, false, false

about 4 years ago · Juan Pablo Isaza Report

0

El método [indexOf] devuelve el primer índice de un elemento dado que se puede encontrar en la matriz. Si no existe, devuelve - 1. Entonces, el valor [indexOf] de los últimos 10 es 4.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!